package vtplayer;

import controller.services.impl.PlaylistPersistenceServiceImpl;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import model.mp3.MP3Info;
import model.mp3.MP3Object;
import model.mp3.impl.MP3InfoImpl;
import model.mp3.impl.MP3ObjectImpl;

public class TestingBench {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

//        AudioInputStream din = null;
//        try {
//
//            File file = new File("Test.mp3");
//            AudioInputStream in = AudioSystem.getAudioInputStream(file);
//            AudioFormat baseFormat = in.getFormat();
//            AudioFormat decodedFormat = new AudioFormat(
//                    AudioFormat.Encoding.PCM_SIGNED,
//                    baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
//                    baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
//                    false);
//            //get mp3 properties
//            AudioFileFormat baseFileFormat = null;
//            baseFileFormat = AudioSystem.getAudioFileFormat(file);
//            baseFormat = baseFileFormat.getFormat();
//// TAudioFileFormat properties
//            if (baseFileFormat instanceof TAudioFileFormat) {
//                Map properties = ((TAudioFileFormat) baseFileFormat).properties();
//                String key = "author";
//                String durationKey = "duration";
//                String titleKey = "title";
//                String albumKey = "album";
//                String val = (String) properties.get(key);
//                System.out.println("author " + val);
//
//                Long duration = (Long) properties.get(durationKey);
//                System.out.println("duration " + duration);
//
//                String title = (String) properties.get(titleKey);
//                System.out.println("title " + title);
//
//                String album = (String) properties.get(albumKey);
//                System.out.println("album " + album);
//
//                key = "mp3.id3tag.v2";
//                InputStream tag = (InputStream) properties.get(key);
//                System.out.println("tag " + tag);
//            }
//// TAudioFormat properties
//            if (baseFormat instanceof TAudioFormat) {
//                Map properties = ((TAudioFormat) baseFormat).properties();
//                String key = "bitrate";
//                Integer val = (Integer) properties.get(key);
//                System.out.println("bitrate " + val);
//            }
//            //get mp3 properties
//
//            din = AudioSystem.getAudioInputStream(decodedFormat, in);
//            DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
//            SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
//            if (line != null) {
//                line.open(decodedFormat);
//                byte[] data = new byte[4096];
//                // Start
//                line.start();
//
//                int nBytesRead;
//                while ((nBytesRead = din.read(data, 0, data.length)) != -1) {
//                    line.write(data, 0, nBytesRead);
//                }
//                // Stop
//                line.drain();
//                line.stop();
//                line.close();
//                din.close();
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            if (din != null) {
//                try {
//                    din.close();
//                } catch (IOException e) {
//                }
//            }
//        }

        
        PlaylistPersistenceServiceImpl service = new PlaylistPersistenceServiceImpl();

//        List<MP3Object> playlist = new ArrayList<>();
//            MP3Object mp3Object = new MP3ObjectImpl();
//            MP3Info mp3Info = new MP3InfoImpl();
//            mp3Info.setArtist("Pink Floyd");
//            mp3Info.setTrackName("High hopes");
//            mp3Info.setLength(Long.MIN_VALUE);
//            
//            mp3Object.setMp3Info(mp3Info);
//            mp3Object.setMp3File(new File("Test.mp3"));
//            
//            playlist.add(mp3Object);
//            
//            mp3Object = new MP3ObjectImpl();
//            mp3Info = new MP3InfoImpl();
//            mp3Info.setArtist("Inna");
//            mp3Info.setTrackName("HOT");
//            mp3Info.setLength(Long.MIN_VALUE);
//            
//            mp3Object.setMp3Info(mp3Info);
//            mp3Object.setMp3File(new File("Test2.mp3"));
//            
////            playlist.add(mp3Object);
//        
//        service.saveData(playlist);
        
        List<MP3Object> readData = service.readData();
        System.out.println(readData.size());
//        SoundJLayer soundToPlay = new SoundJLayer("Test.mp3");
//        try {
//            soundToPlay.play();
//            Thread.currentThread().sleep(2000);//sleep for 1000 ms
//
////            soundToPlay.stop();
//        } catch (InterruptedException ie) {
//            //If this thread was intrrupted by nother thread 
//        }
    }

}
